import { rawRequestClient } from '#/api/request';

// 资源接口类型定义
export interface Resource {
  id?: number;
  code: string;
  name: string;
  description?: string;
  type?: string;
  clientId?: string;
  parentId?: number;
  actions?: string[];
  createdAt?: string;
  createdBy?: string;
}

export interface ResourceRegister {
  clientId: string;
  resources: Omit<Resource, 'id' | 'createdAt' | 'createdBy'>[];
}

// 获取资源列表
export function getResourceList(params?: {
  page?: number;
  size?: number;
  code?: string;
  name?: string;
  type?: string;
  clientId?: string;
  parentId?: number;
}) {
  return rawRequestClient.get(`${import.meta.env.VITE_AUTH_SERVER}/resources`, { params });
}

// 创建资源
export function createResource(data: Omit<Resource, 'id' | 'createdAt' | 'createdBy'>) {
  return rawRequestClient.post(`${import.meta.env.VITE_AUTH_SERVER}/resources`, data);
}

// 注册资源
export function registerResources(data: ResourceRegister) {
  return rawRequestClient.post(`${import.meta.env.VITE_AUTH_SERVER}/resources/register`, data);
}

// 获取资源详情
export function getResourceDetail(id: number) {
  return rawRequestClient.get(`${import.meta.env.VITE_AUTH_SERVER}/resources/${id}`);
}

// 更新资源
export function updateResource(id: number, data: Omit<Resource, 'id' | 'createdAt' | 'createdBy'>) {
  return rawRequestClient.put(`${import.meta.env.VITE_AUTH_SERVER}/resources/${id}`, data);
}

// 删除资源
export function deleteResource(id: number) {
  return rawRequestClient.delete(`${import.meta.env.VITE_AUTH_SERVER}/resources/${id}`);
}
